package com.github.elliot.usercenter.dao;

import com.github.elliot.usercenter.po.Permission;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;

import java.util.List;

@Repository
public interface PermissionRepository extends R2dbcRepository<Permission, Integer> {

    @Query(value = "SELECT d.backend_url FROM user_rel_role a LEFT JOIN role b ON a.role_no=b.role_no LEFT JOIN role_rel_permission c ON b.role_no=c.role_no LEFT JOIN permission d ON c.permission_no=d.permission_no WHERE a.user_no= :userNo")
    Flux<Permission> findPermissionListByUserNo(String userNo);

    @Query(value = "select a.permission_no from role_rel_permission a where a.role_no = :roleNo")
    Flux<String> findPermissionListByRoleNo(String roleNo);

    @Query(value = "select backend_url from permission where permission_no in (:permissionNoList)")
    Flux<String> findBackendUrlListByPermissionNo(List<String> permissionNoList);
}
